package org.example.system.dubbo;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.example.api.system.RemoteOauthClientService;
import org.example.api.system.domain.vo.RemoteOauthClientVo;
import org.example.common.core.utils.MapstructUtils;
import org.example.system.domain.SysOauthClient;
import org.example.system.domain.vo.SysOauthClientVo;
import org.example.system.mapper.SysOauthClientMapper;
import org.springframework.stereotype.Service;

/**
 * 客户端管理
 */
@Slf4j
@Service
@DubboService
@RequiredArgsConstructor
public class RemoteOauthClientServiceImpl implements RemoteOauthClientService {

    private final SysOauthClientMapper baseMapper;

    @Override
    public RemoteOauthClientVo loadClientByClientId(String clientId) {
        SysOauthClientVo clientDetailsVo= baseMapper.selectVoOne(Wrappers.lambdaQuery(SysOauthClient.class)
                .eq(SysOauthClient::getDelFlag,"0")
                .eq(SysOauthClient::getStatus,"0")
                .eq(SysOauthClient::getClientId,clientId)
                .last("limit 1")
        );
        return MapstructUtils.convert(clientDetailsVo, RemoteOauthClientVo.class);
    }
}
